package utl.mofen.handler;

import com.google.gson.JsonObject;

public class JSonConfigReader {
	/**
	 * 从配置中jsonConfig.conn)中读取idKey(main,sys)的配�?
	 * @param jsonConfig
	 * @return
	 */
	public static String getdbid(JsonObject jsonConfig, String idKey) {
		String ret = "";
		if (jsonConfig.has("config")) {
			JsonObject obj = jsonConfig.get("config").getAsJsonObject();
			if (obj.has("conn"))
			{
				obj = obj.get("conn").getAsJsonObject();
				if (obj.has(idKey)) {
					ret = obj.get(idKey).getAsString();
				}
			}
		}
		return ret;
	}
	
	public static boolean getIsTrace(JsonObject jsonConfig)
	{
		boolean ret = false;
		if (jsonConfig.has("config")) {
			JsonObject obj = jsonConfig.get("config").getAsJsonObject();			
			if (obj.has("trace"))
			{
				ret = obj.get("trace").getAsBoolean();
			}
			obj = null;
		}
		return ret;
	}
	
	public static boolean getWithTran(JsonObject jsonConfig)
	{
		boolean ret = false;
		if (jsonConfig.has("config")) {
			JsonObject obj = jsonConfig.get("config").getAsJsonObject();
			if (obj.has("withTrans"))
			{
				ret = obj.get("withTrans").getAsBoolean();
			}
			obj = null;
		}
		return ret;
	}
	public static String getVersion(JsonObject jsonConfig)
	{
		String ret = "";
		if (jsonConfig.has("config")) {
			JsonObject obj = jsonConfig.get("config").getAsJsonObject();
			if (obj.has("ver"))
			{
				ret = obj.get("ver").getAsString();
			}
			obj = null;
		}
		return ret;
	}

}
